package com.uenpay.im.ui.old.activity.publicnumber;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;



/**
 * @author SL
 * @created 2016-1-8 上午10:27:35
 * @copyRight http://www.qiyunxin.com
 * @function 设置公众号消息
 */
public class SetMsgPublicNumberInvokeItem extends BaseHttpInvokeItem {
	public class SetMsgPublicNumberInvokeItemResult extends HttpInvokeResult {
		public ArrayList<PublicNumEntity> arrayList = new ArrayList<PublicNumEntity>();
	}

	public SetMsgPublicNumberInvokeItemResult getOutput() {
		return (SetMsgPublicNumberInvokeItemResult) GetResultObject();
	}

	public SetMsgPublicNumberInvokeItem(String publicnoid, int push) {
		String url = APIConfiguration.getBaseUrl()
				+ "PublicNo/PublicNo/msgSetting?publicnoid=" + publicnoid + "&push="
				+ push + "&" + APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		SetMsgPublicNumberInvokeItemResult result = new SetMsgPublicNumberInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
	
		return result;
	}
}
